﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.Mvc;
using IInject.Web.Mvc.Tests.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IInject.Web.Mvc.Tests
{
	[TestClass]
	public class IInjectBootstrapperTests
	{
		[TestMethod]
		public void InitializeTest()
		{
            var bootstrapper = new IInjectBootstrapper(new Container());
            bootstrapper.Initialize();
            Assert.AreEqual(typeof(IInjectDependencyResolver), DependencyResolver.Current.GetType());
            
            var controllerActivator = bootstrapper.Container.Get<IControllerActivator>();
            Assert.AreEqual(typeof(IInjectControllerActivator), controllerActivator.GetType());
		}

        [TestMethod]
		public void MapControllersTest()
        {
            var container = new Container();
            IInjectBootstrapper.Initialize(container);
            IInjectBootstrapper.MapControllers(container, Assembly.GetExecutingAssembly());
            
            var controller = container.Get(typeof(HomeController));
            Assert.AreEqual(typeof(HomeController), controller.GetType());
        }

        [TestMethod]
		public void MapControllersMultipleAssembliesTest()
        {
            var container = new Container();
            IInjectBootstrapper.Initialize(container);
			IInjectBootstrapper.MapControllers(container);

            var controller = container.Get(typeof(HomeController));
            Assert.AreEqual(typeof(HomeController), controller.GetType());
        }

        [TestMethod]
		public void MapFiltersTest()
        {
            var container = new Container();
            IInjectBootstrapper.Initialize(container);
			IInjectBootstrapper.MapFilters(container, Assembly.GetExecutingAssembly());

            var filters = container.GetAll<IActionFilter>();
            Assert.AreEqual(typeof(List<IActionFilter>), filters.GetType());
            Assert.AreEqual(3, filters.Count());
        }

        [TestMethod]
		public void MapFiltersMultipleAssembliesTest()
        {
            var container = new Container();
            IInjectBootstrapper.Initialize(container);
			IInjectBootstrapper.MapFilters(container);

            var filters = container.GetAll<IActionFilter>();
            Assert.AreEqual(typeof(List<IActionFilter>), filters.GetType());
            Assert.AreEqual(3, filters.Count());
        }
	}
}
